package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.enums.DevelopOrderStatusEnum;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizDevelopOrder;
import com.member.shop.service.ISysBizDevelopOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【发展会员数订单】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-01-09
 **/
@RestController
@RequestMapping("/shop/developOrder")
public class SysBizDevelopOrderController extends BaseController {
    @Resource
    private ISysBizDevelopOrderService sysBizDevelopOrderService;

    /**
     * 查询发展会员数订单列表
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizDevelopOrder sysBizDevelopOrder) {
        startPage();
        List<SysBizDevelopOrder> list = sysBizDevelopOrderService.selectSysBizDevelopOrderList(sysBizDevelopOrder);
        return getDataTable(list);
    }

    /**
     * 导出发展会员数订单列表
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:export')")
    @Log(title = "发展会员数订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizDevelopOrder sysBizDevelopOrder) {
        LambdaQueryWrapper<SysBizDevelopOrder> queryWrapper = new LambdaQueryWrapper<SysBizDevelopOrder>();
        List<SysBizDevelopOrder> list = sysBizDevelopOrderService.selectSysBizDevelopOrderList(queryWrapper);
        ExcelUtil<SysBizDevelopOrder> util = new ExcelUtil<SysBizDevelopOrder>(SysBizDevelopOrder.class);
        util.exportExcel(response, list, "发展会员数订单数据");
    }

    /**
     * 获取发展会员数订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizDevelopOrderService.selectSysBizDevelopOrderById(id));
    }

    /**
     * 新增发展会员数订单
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:add')")
    @Log(title = "发展会员数订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizDevelopOrder sysBizDevelopOrder) {
        return toAjax(sysBizDevelopOrderService.insertSysBizDevelopOrder(sysBizDevelopOrder));
    }

    /**
     * 修改发展会员数订单
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:edit')")
    @Log(title = "发展会员数订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizDevelopOrder sysBizDevelopOrder) {
        return toAjax(sysBizDevelopOrderService.updateSysBizDevelopOrder(sysBizDevelopOrder));
    }

    /**
     * 发货
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:edit')")
    @Log(title = "发展会员数发货", businessType = BusinessType.UPDATE)
    @PostMapping("/sendGoods")
    public AjaxResult sendGoods(@RequestBody SysBizDevelopOrder sysBizDevelopOrder) {
        sysBizDevelopOrder.setStatus(DevelopOrderStatusEnum.SHIPPED.getKey());
        return toAjax(sysBizDevelopOrderService.updateSysBizDevelopOrder(sysBizDevelopOrder));
    }
    /**
     * 删除发展会员数订单
     */
    @PreAuthorize("@ss.hasPermi('shop:developOrder:remove')")
    @Log(title = "发展会员数订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizDevelopOrderService.deleteSysBizDevelopOrderByIds(ids));
    }
}
